﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FTchina;

public partial class error : System.Web.UI.Page
{
    private string ErrorLookup(int id)
    {
         
        switch (id)
        {
            case 1000:
                return "指定数据库不存在";
            case 1001:
                return "指定存储过程不存在";
            case 1002:
                return "指定表单不存在";
            case 1003:
                return "指定字段不存在";
            case 2001:   
                return "无法读取数据库属性，请检查权限";
            case 2002:   
                return "无法连接到数据库，请检查用户名密码是否正确，是否有访问指定数据库的权限";
            case 3001:
                return "ID列不允许删除";
            case 3002:
                return "CreatDateTime列不允许删除";
            case 3003:
                return "一个表单至少要包含一个字段";
            case 7700:
                return "模板参数错误";
            case 9980:
                return "请检查表单名参数";
            case 9981:
                return "请检查表单ID参数";
            case 9000:
                return "请通过客户端登陆系统";
            case 9001:
                return "用户名或密码错误";
            case 9002:
                return "请填写用户名或密码";
            case 9003:
                return "验证码错误";
            case 9999:
                return "参数错误";
            case 404:
                return "未找到页面，请检查地址参数";
            case 403:
                return "页面错误，请检查地址参数";

            default:
                return "发生了未知错误";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

         basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());

        // There are two kinds of errors - custom errors with numbers, and uncaught exceptions
        if (Request["error"] != null)
        {
            ErrorLabel.Text = String.Format("错误 {0}: {1}", Server.HtmlEncode(Request["error"]), ErrorLookup(Convert.ToInt32(Request["error"])));
        }
        else if (Request["errormsg"] != null || Request["stacktrace"] != null)
        {
            ErrorLabel.Text = "错误信息: <br>" + Request["errormsg"].Replace("\n", "<br>") + "<br><br>" +
                              "堆栈跟踪: <br>" + Request["stacktrace"].Replace("\n", "<br>");
        }
         
        else
        {
            

            Exception x = (Exception)Application["Error"];

            while (x != null)
            {
                ErrorLabel.Text += x.Message.Replace("\n", "<br>") + "<br><br>" + x.StackTrace.Replace("\n", "<br>") + "<br><hr><br>";
                x = x.InnerException;
            }

            Application.Remove("Error");
            UImsg.PageRender(ErrorLabel.Text);
        }
    }

    
}
